package com.winit.projectPlan.repository;

import com.winit.projectPlan.model.ProjectPlan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Component
public class ProjectPlanRepositoryExt {
    private static Logger log = LoggerFactory.getLogger(ProjectPlanRepositoryExt.class);

    @PersistenceContext
    private EntityManager entityManager;

    @Transactional
    public void updateProjectPlanById(ProjectPlan projectPlan){
        ProjectPlan entity = entityManager.find(ProjectPlan.class, projectPlan.getProjectPlanId());
        if (entity == null){
            log.error("no projectPlan found for project_plan_id:" + projectPlan.getProjectPlanId() + ", update aborted");
            return;
        }
        if (null != projectPlan.getProjectPlanIsDel()){
            entity.setProjectPlanIsDel(projectPlan.getProjectPlanIsDel());
        }
        if (null != projectPlan.getProjectPlanName()){
            entity.setProjectPlanName(projectPlan.getProjectPlanName());
        }
        if (null != projectPlan.getProjectPlanChargerAccount()){
            entity.setProjectPlanChargerAccount(projectPlan.getProjectPlanChargerAccount());
        }
        if (null != projectPlan.getProjectPlanChargerRealname()){
            entity.setProjectPlanChargerRealname(projectPlan.getProjectPlanChargerRealname());
        }
        if (null != projectPlan.getProjectPlanCreaterAccount()){
            entity.setProjectPlanCreaterAccount(projectPlan.getProjectPlanCreaterAccount());
        }
        if (null != projectPlan.getProjectPlanCreaterRealname()){
            entity.setProjectPlanCreaterRealname(projectPlan.getProjectPlanCreaterRealname());
        }
        if (null != projectPlan.getProjectPlanCreateTime()){
            entity.setProjectPlanCreateTime(projectPlan.getProjectPlanCreateTime());
        }
        if (null != projectPlan.getProjectPlanDesc()){
            entity.setProjectPlanDesc(projectPlan.getProjectPlanDesc());
        }
        if (null != projectPlan.getProjectPlanStatus()){
            entity.setProjectPlanStatus(projectPlan.getProjectPlanStatus());
        }
        if (null != projectPlan.getProjectPlanStartupTime()){
            entity.setProjectPlanStartupTime(projectPlan.getProjectPlanStartupTime());
        }
        if (null != projectPlan.getProjectPlanOnlineTime()){
            entity.setProjectPlanOnlineTime(projectPlan.getProjectPlanOnlineTime());
        }
        if (null != projectPlan.getProjectPlanBusiness()){
            entity.setProjectPlanBusiness(projectPlan.getProjectPlanBusiness());
        }
        if (null != projectPlan.getUplanId()){
            entity.setUplanId(projectPlan.getUplanId());
        }
        if (null != projectPlan.getProjectPlanCode()){
            entity.setProjectPlanCode(projectPlan.getProjectPlanCode());
        }


        if (null != projectPlan.getProjectPlanPdmAccount()){
            entity.setProjectPlanPdmAccount(projectPlan.getProjectPlanPdmAccount());
        }
        if (null != projectPlan.getProjectPlanPdmRealname()){
            entity.setProjectPlanPdmRealname(projectPlan.getProjectPlanPdmRealname());
        }
        if (null != projectPlan.getRisk()){
            entity.setRisk(projectPlan.getRisk());
        }
        entityManager.merge(entity);
        entityManager.flush();
    }
}
